package com.kotei.util;

import java.util.concurrent.*;

public class ThreadUtils {

    int corePoolSize = 5;    // 核心线程数
    int maxPoolSize = 10;    // 最大线程数
    long keepAliveTime = 9; // 空闲线程存活时间(秒)
    BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(1000); // 工作队列
    ExecutorService customThreadPool;
    public ThreadUtils() {
        customThreadPool = new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                workQueue,
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy() // 拒绝策略
        );
    }


    public ExecutorService getCustomThreadPool() {
        return customThreadPool;
    }
}
